﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MethodWorx.CMS.Plugins;

namespace MethodWorx.CMS.Workflow.IfContainsData
{
    public class IfContainsDataWorkflowComponent : WorkflowComponent<IfContainsDataConfigurationController>
    {
        public IfContainsDataWorkflowComponent(Plugin plugin)
            : base(plugin)
        {
        }

        public static Guid ComponentId = Guid.Parse("{74652F48-2AD6-496C-A068-D2CE106414B3}");

        public override Guid Id
        {
            get { return ComponentId;  }
        }

        public override string Category
        {
            get { return "Flow";  }
        }

        public override string Name
        {
            get { return "If Contains Data";  }
        }

        public override string Description
        {
            get { return "Provides program flow based on existance of data";  }
        }

        public override string View
        {
            get { return "IfContainsDataConfigurationView.ascx";  }
        }

        public override StepExecutionResult Execute(IWorkflowExecutionContext context, IWorkflowConfiguration configuration)
        {
            var c = (IfContainsDataConfiguration) configuration;
            var v = context.GetWorkflowValue(c.VariableName);
            if (v != null)
                return StepExecutionResult.Ok(0);
            else
                return StepExecutionResult.Ok(1);
                
        }
    }
}
